package uk.ac.cam.cl.projectcharlie2010.physicalboard;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import ch.nostromo.tiffanys.game.move.Move;

public class FakePhysicalBoardController implements PhysicalBoardController {

	private PhysicalBoardControllerListener listener;
	private BufferedReader consoleReader;

	public FakePhysicalBoardController(PhysicalBoardControllerListener listener) {
		this.listener = listener;
		InputStreamReader isr = new InputStreamReader(System.in);
		consoleReader = new BufferedReader(isr);
	}
	@Override
	public void executePhysicalMove(final Move move, String FEN) {

		Thread runner = new Thread() {
			@Override
			public void run() {
				String moveCompleted = "NOTOK";
				while(!moveCompleted.equals("OK")) {
					try {
						System.out.println("Do physical move from " + move.getFrom() + " to " + move.getTo());
						System.out.println("Type OK when physical move has been completed:");
						moveCompleted = consoleReader.readLine();
					} catch (IOException e) {
						e.printStackTrace();
					}
					listener.executePhysicalMoveFinished();
				}
			}
		};
		System.out.println("FakePhys executePM 1");
		runner.start();
		System.out.println("FakePhys executePM 2");

	}
	@Override
	public void updateBackgroundCeiling() {
		// TODO Auto-generated method stub
		
	}



}
